package com.lmh.ymw.service.product;

import com.lmh.ymw.entity.Product;
import com.lmh.ymw.entity.ProductCategory;
import com.lmh.ymw.mapper.product.ProductCategoryDao;
import com.lmh.ymw.mapper.product.ProductDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

@Service
public class ProductCategoryServiceImpl implements ProductCategoryService{
    @Autowired
    private ProductCategoryDao productCategoryDao;
    @Autowired
    private ProductDao productDao;

    @Override
    public List<ProductCategory> caidan() {

        List<ProductCategory> yiji = productCategoryDao.yiji();
        List<Product> shangping;
        for (ProductCategory p1 : yiji){
            List<ProductCategory> erji = productCategoryDao.ersanji(p1.getId());

            p1.setZl(erji);
            for (ProductCategory p2 : erji){

                List<ProductCategory> sanji = productCategoryDao.ersanji(p2.getId());
                p2.setZl(sanji);
                for (ProductCategory p3: sanji
                     ) {
                    shangping=productDao.selectProduct(p1.getId());
                    p3.setProducts(shangping);
                }
            }
        }

        return yiji;
    }

    @Override
    public ProductCategory getById(Integer id) {
        return productCategoryDao.selectByPrimaryKey(id);
    }

    @Override
    public List<ProductCategory> queryProductCategorylist(ProductCategory params) {
        List<ProductCategory> productCategories = productCategoryDao.queryProductCategorylist(params);
        return productCategories;
    }

    @Override
    public int modifyProductCategory(ProductCategory productCategory) {
        return productCategoryDao.updateByPrimaryKeySelective(productCategory);
    }

    @Override
    public int addProductCategory(ProductCategory productCategory) {
        return productCategoryDao.insertSelective(productCategory);
    }

    @Override
    public int deleteById(Integer id) {
        int i = productCategoryDao.deleteByPrimaryKey(id);
        return i;
    }

}
